﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using BLL;
using Models;

namespace carpool.shenyanhong
{
    /// <summary>
    /// ProcessLogin 的摘要说明
    /// </summary>
    public class ProcessLogin : IHttpHandler
    {
        string number = "";
        string pwd = "";
        public void ProcessRequest(HttpContext context)
        {
            string xiaoxi = "{{\"code\":\"{0}\",\"msg\":\"{1}\"}}";

            number = context.Request["number"];
            pwd = context.Request["pwd"];
            bool result = CheckLogin();
            if (result)
            {
                //登录成功，跳转到主页面
                //添加成功，返回JSON格式字符串
                context.Response.Write(string.Format(xiaoxi, 1, "登录成功"));
            }
            else
            {
                context.Response.Write(string.Format(xiaoxi, 0, "登录失败，是否已经注册？"));
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
        private bool CheckLogin()
        {
            //留着
            //创建一个model
            UserInfo model = new UserInfo();
            model.Number = number;
            model.PassWord = pwd;
            //调用BLL层验证用户和密码是否存在
            return UserInfoBLL.Login(model);
        }
    }
}